<template>
  <div class="page">
    <div class="addContent">
      <el-card class="box-card">
        <!-- 头部 -->
        <div slot="header" class="clearfix">
          <span>更改成员信息</span>
          <!-- 关闭按钮 -->
          <el-button
            style="float: right; padding:10px 30px"
            type="text"
            icon="el-icon-close"
            @click="close"
          ></el-button>
        </div>
        <!-- 更改信息表单 -->
        <el-form ref="form" :model="update" label-width="80px">
          <el-form-item label="角色名称">
            <el-select v-model="update.role" placeholder="请选择角色名称">
              <el-option label="超级管理员" value="超级管理员"></el-option>
              <el-option label="网络管理员" value="网络管理员"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="姓名">
            <el-input v-model="update.name"></el-input>
          </el-form-item>
          <el-form-item label="部门名称">
            <el-cascader v-model="region" :options="options" @change="handleChange"></el-cascader>
          </el-form-item>
          <el-form-item label="上级名称">
            <el-select v-model="update.superior" placeholder="请选择上级名称">
              <el-option label="总公司" value="总公司"></el-option>
              <el-option label="上海分公司" value="上海分公司"></el-option>
              <el-option label="杭州分公司" value="杭州分公司"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit" :plain="true">更改</el-button>
            <el-button @click="close">取消</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import { updateMember } from "@/assets/api/Rolerequest.js";
export default {
  props: ["upId"],
  data() {
    return {
      // 部门
      region: [],
      //   传递给php文档的参数---添加成员
      update: {
        id: "",
        role: "",
        name: "",
        // 部门
        department: "",
        // 上级
        superior: ""
      },
      isShowUp: false,
      //   部门下拉框的参数
      value: [],
      options: [
        //   顶级
        {
          value: "顶级",
          label: "顶级",
          children: [
            {
              value: "总公司",
              label: "总公司",
              children: [
                {
                  value: "开发部",
                  label: "开发部"
                },
                {
                  value: "运营部",
                  label: "运营部"
                },
                {
                  value: "战略部",
                  label: "战略部"
                },
                {
                  value: "人事部",
                  label: "人事部"
                },
                {
                  value: "行政部",
                  label: "行政部"
                }
              ]
            },
            {
              value: "上海分公司",
              label: "上海分公司",
              children: [
                {
                  value: "运维部",
                  label: "运维部"
                },
                {
                  value: "销售",
                  label: "销售"
                }
              ]
            },
            {
              value: "杭州分公司",
              label: "杭州分公司",
              children: [
                {
                  value: "微商部",
                  label: "微商部"
                },
                {
                  value: "软件部",
                  label: "软件部"
                }
              ]
            }
          ]
        }
      ],
      //   新增成员信息
      info: {}
    };
  },
  methods: {
    //   按钮---更改成员
    onSubmit() {
      // 方法1：封装了axios    post请求
      this.id = this.upId;
      updateMember(this.update)
        .then(res => {
          console.log(res.data);
          if (res.data.code == 3000) {
            this.$message({
              message: "更改成功",
              type: "success"
            });
            setTimeout(() => {
              this.$emit("sends", this.isShowUp);
            }, 2000);
          } else {
            this.$message({
              message: "未知错误",
              type: "fail"
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    handleChange(region) {
      this.update.department = region[2];
    },
    close() {
      // this.isShowUp = false
      this.$emit("sends", this.isShowUp);
    }
  },
  watch: {
    upId() {
      this.update.id = this.upId;
      // console.log(this.update.id);
    }
  }
};
</script>

<style lang="stylus" scoped>
.box-card >>> .el-card__header {
  padding: 0;
  line-height: 40px;
  background-color: #f8f8f8;
}

.clearfix span {
  margin: 0 0 0 20px;
  color: #333;
  font-size: 14px;
}

.el-button--text {
  font-size: 20px;
}

.addContent >>> .el-card__body {
  background-color: #edecec;
}

.el-form {
  background-color: #fff;
  padding: 20px;
  overflow: hidden;
}

.el-form >>> .el-form-item {
  width: 300px;
  float: left;
}

.el-form-item >>> .el-input {
  outline: none;
  border-top: 0;
  border-left: 0;
  border-right: 0;
}
</style>
